import {
  CoolController,
  BaseController,
  CoolUrlTag,
  TagTypes,
  CoolTag,
} from '@cool-midway/core';
import { Body, Get, Inject, Post, Query } from '@midwayjs/core';
import { BizWorkerListEntity } from '../../entity/list';
import { BizWorkerListAppService } from '../../service/listApp';

/**
 * app相关接口
 */
@CoolUrlTag({
  key: TagTypes.IGNORE_TOKEN,
  value: ['page', 'info'],
})
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: BizWorkerListEntity,
  service: BizWorkerListAppService,
  pageQueryOp: {
    fieldEq: ['workType', 'status'],
    keyWordLikeFields: [],
  },
})
export class BizWorkerListAppController extends BaseController {
  @Inject()
  bizWorkerListAppService: BizWorkerListAppService;

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/bindWx', { summary: '绑定微信账号' })
  async bindWx(@Body('accountInf') accountInf: any, @Body('wxInf') wxInf: any) {
    return this.ok(
      await this.bizWorkerListAppService.bindWx(accountInf, wxInf)
    );
  }

  @Post('/updatePassword', { summary: '更新密码' })
  async updatePassword(
    @Body('workerId') workerId: number,
    @Body('passwordOld') passwordOld: string,
    @Body('passwordNew') passwordNew: string
  ) {
    return this.ok(
      await this.bizWorkerListAppService.updatePassword(
        workerId,
        passwordOld,
        passwordNew
      )
    );
  }

  @Post('/searchWorkers', { summary: '搜索指定条件的师傅' })
  async searchWorkers(
    @Body('pagination') pagination: any,
    @Body('fieldEq') fieldEq: any
  ) {
    return this.ok(
      await this.bizWorkerListAppService.searchWorkers(pagination, fieldEq)
    );
  }

  @Post('/checkWorkerCanWork', {
    summary: '检测师傅在工期内是否有空挡排期 存在空挡则返回师傅个人信息',
  })
  async checkWorkerCanWork(
    @Body('workerId') workerId: number,
    @Body('startDate') startDate: string,
    @Body('endDate') endDate: string,
    @Body('needData') needData: boolean // 是否返回工人信息
  ) {
    return this.ok(
      await this.bizWorkerListAppService.checkWorkerCanWork(
        workerId,
        startDate,
        endDate,
        needData
      )
    );
  }
}
